#!/bin/bash -x
echo "当前运行的进程名:" $0 "当前进程:" $$ "一共有: " $# " 个参数,所有参数内容是"$* ", 他们分别是" $0 $1 $2 $3 $4
#条件测试
A=10
B=20
C=30
if test $A -eq $B;then
    echo "A=B"
fi

if test $A -gt $B;then
    echo "A>B"
fi

if test $A -lt $B;then
   echo "A<=B"
fi

if test $A -ne $B;then
    echo "A NE B IS TRUE"
fi
C=$[ $B*10+1 ]
echo $C

# maverick@localhost:/project/embeded-linux-c/bashdir$ ./test.sh
# 当前运行的进程名: ./test.sh 当前进程: 14217 一共有:  0  个参数,所有参数内容是 , 他们分别是 ./test.sh
# A=B
# A>B
# A<B
# A NE B IS TRUE
# 201
# maverick@localhost:/project/embeded-linux-c/bashdir$

##################################################################################################################3333

echo "1= "$1 "2= "$2
if [ -z "$1" ] || [ -z "$2" ] ;then
    echo "Please enter file name!"
    exit 1
else
    echo "NEXT......."
fi

if [ -e "$2" ]
then
    echo "The file alraday exists"  
    until [ ! -d $2 ];do
        sleep 2
    done
fi

if mv "$1" "$2";then
    echo "move succesully!"
else
    echo "move error!"
fi

# maverick@localhost:/project/embeded-linux-c/bashdir$ ls
# test.sh  test.txt  test2.txt
# maverick@localhost:/project/embeded-linux-c/bashdir$ ./test.sh test.txt test2.txt
# 当前运行的进程名: ./test.sh 当前进程: 14700 一共有:  2  个参数,所有参数内容是test.txt test2.txt , 他们分别是 ./test.sh test.txt test2.txt
# A<=B
# A NE B IS TRUE
# 201
# 1= test.txt 2= test2.txt
# NEXT.......
# The file alraday exists
# move succesully!
# maverick@localhost:/project/embeded-linux-c/bashdir$

# 使用 for 循环
counter=0
for files in *
do
    echo $files "------------------------"
    counter=$(($counter+1))
    echo "当前数字是: $counter"
done

echo "There are $counter files in `pwd` to process"

for i in {1..5}
do
    echo "当前数字是: $i"
done

count=1
while [ $count -le 3 ]
do
    echo "Count: $count"
    count=$(( count + 1 ))
done

until [ ! $counter -lt 2 ];do
    sleep 1
    counter=$(($counter+1))
    echo "we are waiting for "$[10-$counter]" seconds"
done

echo "I am now reading key input"
#读取一行，
read Keypress

case "$Keypress" in
    [A-Z]) 
        echo "UPPER"
        ;;
    [a-z]) 
        echo "lower"
        ;;
    [0-9]) 
        echo "dight"
        ;;
    *) 
        echo "OTHER"
        ;;
esac
echo arg
# exec "test............"
trap 'echo "接收到信号，脚本即将退出。"; exit 0' SIGINT SIGTERM SIGQUIT

echo "脚本开始执行，按 Ctrl + C、Ctrl + \ 中断，或发送 SIGTERM 信号。"

while true; do
    echo "这是一个无限循环。"
    sleep 1
done


#程序在后台等待启动的所有子进程结束，wait返回的值总是为真。
wait 